#include <ros/ros.h>
#include <functional>
#include "learn_topic_userdef/Product.h"

class Product {
 public:
  Product() {
    msg_pub_ = nh_.advertise<learn_topic_userdef::Product>("product_info", 10);
    timer_ = nh_.createTimer(ros::Duration(0.1), &Product::TimerCallback, this); // 间隔0.1s 回调一次
  }

  ~Product() {

  }

  static void init(int argc, char** argv) {
    ros::init(argc, argv, "product_publisher");
  }

 private:
  ros::Publisher  msg_pub_;
  ros::Timer      timer_;
  ros::NodeHandle nh_;

  void TimerCallback(const ros::TimerEvent& event) {
    learn_topic_userdef::Product product_msg;
    product_msg.name = "LiDAR";
    product_msg.type = learn_topic_userdef::Product::consumer_grade;
    product_msg.function =  "measure range and angle for object.";
    msg_pub_.publish(product_msg);
    ROS_INFO("Publish product info: name:%s,type:%d,function:%s", 
      product_msg.name.c_str(), product_msg.type, product_msg.function.c_str());
  }
  
};


int main(int argc, char** argv) {

  Product::init(argc, argv);
  Product pub;
  ros::spin();

  return 0;
}
